package org.example.eduorder.service.impl;

import org.example.ResultCode.ordervo.CourseWebVoOrder;
import org.example.ResultCode.ordervo.UcenterMemberOrder;
import org.example.eduorder.client.EduClient;
import org.example.eduorder.client.UcenterClient;
import org.example.eduorder.entity.Order;
import org.example.eduorder.mapper.OrderMapper;
import org.example.eduorder.service.OrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.eduorder.utils.OrderNoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author lining
 * @since 2023-11-09
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
    @Autowired
    private EduClient eduClient;
    @Autowired
    private UcenterClient ucenterClient;
    //1.生成订单
    @Override
     public String createOrders(String courseId, String memberId){
        //通过远程调用根据用户id获取用户信息
        UcenterMemberOrder userInfoOrder=ucenterClient.getUserInfoOrder(memberId);
        //通过远程调用根据课程id获取课程信息
        CourseWebVoOrder courseInfoOrder=eduClient.getCourseInfoOrder(courseId);
        //创建订单对象
        Order order=new Order();
        order.setOrderNo(OrderNoUtil.getOrderNo());
        order.setCourseId(courseId);
        order.setCourseTitle(courseInfoOrder.getTitle());
        order.setCourseCover(courseInfoOrder.getCover());
        order.setTeacherName(courseInfoOrder.getTeacherName());
        order.setTotalFee(courseInfoOrder.getPrice());
        order.setMemberId(memberId);
        order.setMobile(userInfoOrder.getMobile());
        order.setNickname(userInfoOrder.getNickname());
        order.setStatus(0);//支付状态(0:未支付 1:已支付)
        order.setPayType(1);//支付类型(1:微信 2:支付宝)
        baseMapper.insert(order);
        return order.getOrderNo();





    }

}
